REST API: Add finalize endpoint to WP_REST_Attachments_Controller#11168
REST API: Add finalize endpoint to WP_REST_Attachments_Controller#11168adamsilverstein wants to merge 7 commits intoWordPress:trunkfrom
Conversation
Add a `POST /wp/v2/media/{id}/finalize` endpoint that triggers the
`wp_generate_attachment_metadata` filter after client-side media
processing completes. This ensures server-side plugins (e.g., for
watermarking, CDN sync, custom sizes) can post-process attachments
when client-side processing is active.
The endpoint:
- Reuses `edit_media_item_permissions_check` for authorization
- Re-applies `wp_generate_attachment_metadata` with context 'update'
- Updates attachment metadata and returns the updated attachment
- Is only registered when client-side media processing is enabled
Props adamsilverstein.
See #62243.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Show resolved
Hide resolved
| array( | ||
| 'methods' => WP_REST_Server::CREATABLE, | ||
| 'callback' => array( $this, 'finalize_item' ), | ||
| 'permission_callback' => array( $this, 'finalize_item_permissions_check' ), |
There was a problem hiding this comment.
Shell we use edit_media_item_permissions_check directly as the new method class that function and return the value?
There was a problem hiding this comment.
I feel like the wrapper approach is pretty standard here? or maybe I'm not understanding your suggestion completely?
There was a problem hiding this comment.
Yes but
Can we use single method for both?
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Address remaining code style feedback from @westonruter.
Align equals signs for adjacent variable assignments per WordPress coding standards.
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Looks good to me.
Non-blocking feedback https://github.com/WordPress/wordpress-develop/pull/11168/files#r2915787647
Summary
POST /wp/v2/media/{id}/finalizeREST API endpoint toWP_REST_Attachments_Controllerwp_generate_attachment_metadatafilter with context'update'after client-side media processing completeswp_is_client_side_media_processing_enabled()returns trueContext
When client-side media processing handles image uploads (resizing, thumbnail generation, format conversion), server-side WordPress hooks like
wp_generate_attachment_metadataare bypassed. This endpoint is called after all client-side operations (upload, thumbnail generation, sideloads) are complete, re-triggering the filter so plugins continue to work.Hook usage example
Changes
class-wp-rest-attachments-controller.phpfinalizeroute registration,finalize_item_permissions_check(), andfinalize_item()methodsrest-attachments-controller.php(tests)rest-schema-setup.phpwp-api-generated.jsTest plan
wp_generate_attachment_metadatafilter fires with context'update'Related
Trac ticket: https://core.trac.wordpress.org/ticket/64804
Commit message